<template>
  <div class="dashboard-container">
    <div v-loading="loading" class="app-container" element-loading-text="加载中...">
      <!-- 工具栏 -->
      <page-tools :show-before="true">
        <template #before>
          本月{{ tips.dateRange }}：社保在缴 {{ tips.socialSecurityCount }} 公积金在缴 {{ tips.providentFundCount }} 增员 {{ tips.newsCount }} 减员 {{ tips.reducesCount }} 入职 {{ tips.worksCount }} 离职 {{ tips.leavesCount }}
        </template>
        <template #after>
          <el-button size="mini" type="danger" @click="$router.push('/social_securitys/historicalArchiving')">历史归档</el-button>
          <el-button size="mini" type="primary" @click="$router.push(`/social_securitys/monthStatement?yearMonth=${yearMonth}`)">{{ yearMonth }}报表</el-button>
        </template>
      </page-tools>
      <!-- 筛选组件 -->
      <social-tool />
      <el-card class="hr-block">
        <el-table :data="socialList" style="width: 100%">
          <el-table-column type="index" width="50" label="序号" />
          <el-table-column prop="username" label="姓名" sortable />
          <el-table-column prop="mobile" label="手机" sortable />
          <el-table-column prop="workNumber" label="工号" sortable />
          <el-table-column prop="departmentName" label="部门" sortable width="180" />
          <el-table-column prop="timeOfEntry" label="入职时间" sortable />
          <el-table-column prop="leaveTime" label="离职时间" sortable />
          <el-table-column prop="participatingInTheCity" label="社保城市" width="180" />
          <el-table-column prop="providentFundCity" label="公积金城市" width="180" />
          <el-table-column prop="socialSecurityBase" label="社保基数" />
          <el-table-column prop="providentFundBase" label="公积金基数" />
          <el-table-column label="操作">
            <template #default="obj">
              <el-button type="text" size="mini" @click="$router.push(`/social/detail/${obj.row.id}`)">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-row type="flex" align="middle" justify="center" style="height: 60px">
          <el-pagination
            :total="params.total"
            :current-page="params.page"
            :page-size="params.pageSize"
            layout="prev, pager, next"
            @current-change="pageChange"
          />
        </el-row>
      </el-card>

    </div>
  </div>
</template>

<script>
import { getSettings, getSocialList } from '@/api/social'
import SocialTool from './components/social-tool'
import pageTools from './components/page-tools.vue'

export default {
  name: 'SocialTableIndex',
  components: { SocialTool, pageTools },
  data() {
    return {
      list: [],
      socialList: [],
      yearMonth: '',
      // 筛选条件
      params: {
        page: 1,
        pageSize: 10,
        total: 0,
        departmentChecks: null, // 部门
        providentFundChecks: null, // 公积金城市
        socialSecurityChecks: null// 社保城市
      },
      tips: {},
      loading: false
    }
  },
  created() {
    // 获取社保列表
    this.getSettings()
    this.GetSocialList()
  },
  methods: {
    // 查询企业用户社保列表
    async GetSocialList() {
      this.loading = true
      const res = await getSocialList(this.params)
      console.log(res)
      const { rows, total } = res
      this.socialList = rows
      this.params.total = total
      this.loading = false
    },
    // 查询企业社保配置信息
    async getSettings() {
      const { dataMonth } = await getSettings()
      this.yearMonth = dataMonth
    },
    changeSelectParams(selectParams) {
      console.log(selectParams)
      this.params.departmentChecks = selectParams.departmentChecks.map(item => item.toString())
      this.params.providentFundChecks = selectParams.providentFundChecks.map(item => item.toString())
      this.params.socialSecurityChecks = selectParams.socialSecurityChecks.map(item => item.toString())
      this.params.page = 1
      this.GetSocialList()
    },
    pageChange(page) {
      this.params.page = page // 当前
      this.GetSocialList() // 获取列表数据
    },
    // 导出
    handleExport() {
      // GaolyQQ待实现
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.cont-bod-box {
  padding: 20px;
  background: #fff;
  border-radius: 3px;
  margin-top: 15px;
  margin-bottom: 15px;
  border: 1px solid #ebeef5;
}

</style>
